//
// Created by 董一龙 on 2022/10/13.
//

#ifndef FQUEUE_SEGMENT_QUEUE_H
#define FQUEUE_SEGMENT_QUEUE_H

#include <filesystem>
#include <string>
#include "mmap_queue/mmap_queue.h"

namespace fqueue {

    class segment_queue {

    public:
        struct index_t {
            std::string base_directory;
            int32_t seqnum;

            // 注意生命周期
            [[nodiscard]] std::string to_string() const;
            [[nodiscard]] std::filesystem::path to_path() const;

            bool operator==(index_t const& other) const;
        };

    private:
        index_t m_index;
        std::unique_ptr<mmap_queue> m_pQueue;
    public:
        segment_queue() = delete;

        explicit segment_queue(index_t index);

        [[nodiscard]] index_t const& index();

        [[nodiscard]] index_t next_index();

        [[nodiscard]] size_t capacity() const;

        [[nodiscard]] size_t size() const;

        int enqueue(void const*input, size_t input_length);

        int dequeue(void *output, size_t output_length);
    };

} // fqueue

#endif //FQUEUE_SEGMENT_QUEUE_H
